#include <cstdio>
#include <iostream>

using std::cin;
using std::cout;

typedef long long LL;

const int maxn = 1e5 + 3, maxz = 1e5 + 3;

int pcnt, k;
int vis[maxz], mu[maxz], pri[maxz];
int buk[maxz], cnt[maxz];
LL ans;
LL f[maxz];

inline LL query(int x) {
	LL res = 0;
	for (int i = 1; i * i <= x; ++i) {
		if (x % i == 0) {
			res += mu[i] * f[i];
			if (i * i != x) {
				res += mu[x / i] * f[x / i];
			}
		}
	}
	return res;
}

inline void add(int x) {
	if (x % k) return;
	buk[x]++;
	x /= k;
	ans += query(x);
	for (int i = 1; i * i <= x; ++i) {
		if (x % i == 0) {
			f[i] += 1;
			if (i * i != x) {
				f[x / i] += 1;
			}
		}
	}
}

inline void del(int x) {
	if (x % k || buk[x] == 0) return;
	buk[x]--;
	x /= k;
	for (int i = 1; i * i <= x; ++i) {
		if (x % i == 0) {
			f[i] -= 1;
			if (i * i != x) {
				f[x / i] -= 1;
			}
		}
	}
	ans -= query(x);
}

int main() {
	freopen("number.in", "r", stdin);
	freopen("number.out", "w", stdout);
	std::ios::sync_with_stdio(false);
	cin.tie(NULL), cout.tie(NULL);

	int n;
	cin >> n >> k;
	mu[1] = 1;
	for (int i = 2; i < maxz; ++i) {
		if (vis[i] == false) {
			pri[++pcnt] = i;
			mu[i] = -1;
		}
		for (int j = 1; j <= pcnt && pri[j] * i < maxz; ++j) {
			vis[i * pri[j]] = true;
			if (i % pri[j] == 0) break;
			mu[i * pri[j]] = -mu[i];
		}
	}
	for (int i = 1; i <= n; ++i) {
		int a, b;
		cin >> a >> b;
		switch (a) {
			case 0:
				del(b);
				break;
			case 1:
				add(b);
				break;
		}
		cout << ans << '\n';
	}
	return 0;
}
